package com.qf.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @propram: IntelliJ IDEA
 * @description: 自动填充数据
 * @author: 秦先发
 * @create: 2021-09-24 17:09
 **/
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Object createdTime = getFieldValByName("createTime", metaObject);
        if (createdTime == null) {
            setFieldValByName("createTime", new Date(), metaObject);
        }
        Object status = getFieldValByName("status", metaObject);
        if (status == null) {
            setFieldValByName("status", 1, metaObject);
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {

    }
}
